package com.example.weatherforecast.whtrcdn.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.RecyclerView
import com.example.weatherforecast.R
import com.example.weatherforecast.whtrcdn.entity.WeatherIndexInfo

class WeatherInfoIndexListAdapter(private val context: Context, private val data: List<WeatherIndexInfo>): RecyclerView.Adapter<WeatherInfoIndexListAdapter.IndexViewHolder>() {
    val TAG = WeatherInfoIndexListAdapter::class.java.simpleName
    class IndexViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val layout: LinearLayout = itemView.findViewById(R.id.ll_weather_index)
        val indexName: TextView = itemView.findViewById(R.id.tv_weather_index_name)
        val indexValue = itemView.findViewById<ImageView>(R.id.iv_weather_index_picture)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IndexViewHolder {
        return IndexViewHolder(LayoutInflater.from(context).inflate(R.layout.weather_index_list_item, parent, false))
    }

    override fun onBindViewHolder(holder: IndexViewHolder, position: Int) {
        holder.indexName.text = data[position].name
        holder.layout.setOnClickListener{

            AlertDialog.Builder(context).setMessage(data[position].detail).show()

        }
    }

    override fun getItemCount(): Int {
        Log.i(TAG, "getItemCount: " + data.size)
        return data.size
    }

}